package singleton.regist;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Feng
 * @date 2019/3/10 17:29
 */
public class ContainerSingleton {
    private ContainerSingleton(){}

    private static Map<String, Object> ioc = new ConcurrentHashMap<String, Object>();
    public static Object getBeen(String className){
        synchronized (ContainerSingleton.class){
            if(!ioc.containsKey(className)){
                Object object = null;
                try{
                    object = Class.forName(className).newInstance();
                    ioc.put(className, object);
                }
                catch (Exception e){
                    e.printStackTrace();
                }
                return  object;
            }
            else {
                return ioc.get(className);
            }
        }
    }
}
